<?php


namespace app\admin\model\Shop;



use think\facade\Db;

class ShopGoodsCateRelationModel
{
    /**
     * 数据表名
     * @var string
     */
    protected $name = "shop_goods_cate_relation";

    /**
     * 获取商品分类
     * @param $where
     * @return mixed
     * @throws
     */
    public static function getShopGoodsCateRelationJoinWhere($where)
    {
        array_push($where, ['sgc.is_show','=','1']);
        $field = ['sgc.cate_name', 'sgc.img as cate_img, sgc.sort'];
        $list = Db::name('shop_goods_cate_relation as sgcr')
            ->join('shop_goods_cate as sgc', function ($join) {
                $join->on('sgcr.cate_id', '=', 'sgc.id');
            })
            ->field($field)
            ->where($where)
            ->select()->toArray();
        return $list;
    }

    /**
     * 根据条件查询多条
     * @param $where
     * @return array
     * @throws
     */
    public static function getShopGoodsCateRelationWhereMore($where)
    {
        $list = Db::name('shop_goods_cate_relation')->where($where)->select()->toArray();
        return $list;
    }

    /**
     * 统计
     * @param $where
     * @return int
     */
    public static function getShopGoodsCateRelationCountWhere($where)
    {
        $count = Db::name("shop_goods_cate_relation")->where($where)->count();
        return $count;
    }

    /**
     * 批量添加
     * @param $data
     * @return int
     */
    public static function addShopGoodsCateRelation($data)
    {
        $flag = Db::name("shop_goods_cate_relation")->insertAll($data);
        return $flag;
    }

    /**
     * 删除
     * @param $where
     * @return int
     * @throws
     */
    public static function delShopGoodsCateRelationWhere($where)
    {
        $flag = Db::name('shop_goods_cate_relation')->where($where)->delete();
        return $flag;
    }
}
